<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="cn.kaguyaever.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/7/17
  Time: 14:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme()
            +"://"
            +request.getServerName()
            + ":"
            +request.getServerPort()
            +request.getContextPath()
            +"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>主页</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/webjars/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#endVote").click(function () {
                if (!confirm("你确定要结束投票吗？")) {
                    return false;
                }
            });
            $("#deleteProject").click(function () {
                if (!confirm("你确定要删除项目吗？")) {
                    return false;
                }
            });
        });
    </script>
</head>
<body>
<h1>欢迎回来,${sessionScope.user.username}</h1>
    <c:if test="${empty sessionScope.project}">
        <table>
            <tr>
                <td>你还没有投票项目</td>
            </tr>
            <tr>
                <td>
                    <a href="user/create_project.jsp">创建项目</a>
                </td>
            </tr>
        </table>
    </c:if>
    <c:if test="${not empty sessionScope.project}">
<table>
    <tr>
        <td>你创建的投票项目:</td>
    </tr>
        <tr>
            <td>
                ${sessionScope.project.information}
            </td>
            <td>项目ID:${sessionScope.project.projectId}</td>
        </tr>
        <c:if test="${not empty sessionScope.votes}">
        <c:forEach items="${sessionScope.votes}" var="entry">
            <tr>
                <td>
                    第${entry.num}轮投票:<c:if test="${entry.voteStatus==0}">未开始
                </c:if><c:if test="${entry.voteId==sessionScope.voteId&&entry.voteStatus==0}">
                    <a href="voteServlet?action=chooseJudge">开始投票</a>
                </c:if>
                    <c:if test="${entry.voteStatus==1}">进行中
                        <a href="voteServlet?action=endVote" id="endVote">结束投票</a>
                    </c:if>
                    <c:if test="${entry.voteStatus==2}">已结束</c:if>
                </td>
            </tr>
        </c:forEach>
        </c:if>
    <tr>
            <td>
                <a href="user/create_vote.jsp">添加一轮投票</a>
            </td>
    </tr>
<tr>
    <td>
        <a href="projectServlet?action=projectInformation">投票信息</a>
    </td>
    <td>
        <a href="userServlet?action=manageJudge">用户管理</a>
    </td>
    <td>
        <a href="projectServlet?action=deleteProject" id="deleteProject">删除项目</a>
    </td>
</tr>
</table>
    </c:if>
    <a href="user/mail_verification.jsp">修改密码</a>
    <br>
    <a href="userServlet?action=logout">登出</a>
    <br>
    <span class="errorMsg">
            ${requestScope.msg}
    </span>
</body>
</html>
